<?php

class Reserva_ConsultaController extends Zend_Controller_ActionAquiles {

    public function init() {
        parent::init();
        $this->view->title = 'Consulta Reservas';
    }

    public function indexAction() {
        $filter = new Zend_Filter_Date();
        $data = null;
        if(isset($_REQUEST['data']) && Zend_Date::isDate($_REQUEST['data'])){
            $data = $filter->filter($_REQUEST['data']);
        }else{
            $data = Zend_Date::now()->get('Y/M/d/');
        }
        
        $lista = Application_Model_Mesa::getInstance()->getMesasReserva($data);
        $this->view->mesas = $lista;
        $this->view->data= $filter->filter($data);
    }
    
    public function saveAction() {
        $model = Application_Model_Reserva::getInstance();
        $model->insert($this->getReserva());
        
        return $this->_helper->redirector('index','reserva', 'reserva');
    }
    
    public function validaAction() {
        $resp = new Util_Function_JsonResponse();
        echo Zend_Json::encode(array("erros" => $resp->getErros()), Zend_Json::TYPE_OBJECT);
        die();
    }
    
    private function getReserva(){
        $filter = new Zend_Filter_Date();
        $reserva['nome'] = $_POST['nome'];
        $reserva['telefone'] = $_POST['telefone'];
        $reserva['data'] = $filter->filter($_POST['dia']);
        $reserva['hora'] = $_POST['hora'];
        $reserva['mesa'] = $_POST['mesa'];
        $reserva['hora_saida'] = null;
        return $reserva;
    }

}